class Solution {
public:
    bool lemonadeChange(vector<int>& bills) {

        int num_5 = 0, num_10 = 0, num_20 = 0;

        bool flag = true;
        for (int i = 0; i < bills.size(); i++) {
            if (bills[i] == 10) {
                if (num_5 > 0)
                    num_5--;
                else
                    flag = false;
                num_10++;
            }
            else if (bills[i] == 20) {
                if (num_10 > 0)
                {
                    if (num_5 > 0)
                    {
                        num_10--;
                        num_5--;
                    }
                    else
                        flag = false;
                }
                else
                {
                    if (num_5 >= 3)
                        num_5 -= 3;
                    else
                        flag = false;
                }
                num_20++;
            }
            else {
                num_5++;
            }
        }
        return flag;
    }
};